import 'package:flutter/material.dart';
import './layout/gridViewLayout.dart';
import './layout/project/columnLayoutProject.dart';
import './layout/project/resume.dart';
import './layout/singleColumnLayout.dart';
import './layout/singleLayout.dart';
import './layout/singleListViewBuilderLayout.dart';
import './layout/singleListViewLayout.dart';
import './layout/singleListViewRowLayout.dart';
import './layout/singleRowLayout.dart';
import 'model/card_item.dart'; // 引入 CardItem 类

class PreviewPage extends StatelessWidget {
  final CardItem cardItem; // 新增参数

  const PreviewPage({super.key, required this.cardItem}); // 修改构造函数

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(cardItem.title), // 使用传递的参数
      ),
      body: Center(child: renderContent()),
    );
  }

  // 条件渲染方法
  Widget renderContent() {
    if (cardItem.key == 'single') {
      return SingleLayout(cardItem: cardItem);
    } else if (cardItem.key == 'column_layout_project') {
      return ColumnLayoutProject();
    } else if (cardItem.key == 'row_layout') {
      return SingleRowLayout(cardItem: cardItem);
    } else if (cardItem.key == 'column_layout') {
      return SingleColumnLayout(cardItem: cardItem);
    } else if (cardItem.key == 'listtitle_layout') {
      return SingleListViewLayout(cardItem: cardItem);
    } else if (cardItem.key == 'listview_row_layout') {
      return SingleListViewRowLayout(cardItem: cardItem);
    } else if (cardItem.key == 'listview_builder_layout') {
      return SingleListViewBuilderLayout(cardItem: cardItem);
    } else if (cardItem.key == 'resume_project') {
      return ResumeScreen();
    } else if (cardItem.key == 'gridview_layout') {
      return GridViewLayout(cardItem: cardItem);
    } else {
      return Text(cardItem.content); // 根据需求调整逻辑
    }
  }
}
